package com.lihaozhe.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @author 李昊哲
 * @version 1.0
 * 2021/11/28 13:17
 */
@Slf4j
@Controller
public class RouterController {
    @GetMapping("/toLoginPage")
    public String loginPage() {
        return "login";
    }

    @PostMapping("/toSuccessPage")
    public String successPage() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        User user = (User) authentication.getPrincipal();
        log.info("username = {}", user.getUsername());
        log.info("password = {}", user.getPassword());

        return "success";
    }

    @PostMapping("/toFaieldPage")
    public String faieldPage() {
        return "faield";
    }
}